package com.example.bes017.websocket.demo.websocketserver;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArraySet;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@ServerEndpoint("/ws/{userId}")  // 接口路径 ws://localhost:8087/webSocket/userId;
public class WebSocket {

    @OnOpen
    public void onOpen(Session session, @PathParam(value="userId")String userId) {
        log.info("连接建立");
    }

    @OnClose
    public void onClose() {
        log.info("连接关闭");
    }

    @OnMessage
    public void onMessage(String message, Session session) throws IOException {
        log.info("【websocket消息】收到客户端消息:" + message);
        session.getBasicRemote().sendText("copy that : " + message);
    }
    
}

